<?php
session_start();
// Clear all previous messages.
if($_SESSION['log-err']) session_unregister('log-err');
if($_SESSION['log-info']) session_unregister('log-info');

$year= $_POST['year'];
$grade = $_POST['grade'];
$class = $_POST['class'];
$sub1=$_POST['sub1'];
$sub1=$_POST['sub2'];
$sub1=$_POST['sub3'];
$sub1=$_POST['sub4'];
$sub1=$_POST['sub5'];
$sub1=$_POST['sub6'];
$sub1=$_POST['sub7'];
$sub1=$_POST['sub8'];
$sub1=$_POST['sub9'];
$sub1=$_POST['sub10'];
$sub1=$_POST['sub11'];
$sub1=$_POST['sub12'];



if($year != "" && $grade!="" && $class!=""){
	include('./dbconnection.php');
	// Check whether class is already registerd.
	$query_check = "SELECT * FROM class WHERE year = '$year' AND grade='$grade' AND class='$class' ";


	if($class_exsist = mysql_query($query_check)){
		if(mysql_num_rows($class_exsist)>0){
			// class is already registered.
			$_SESSION['log-err'] = "Class Already Exists.";
		}else{
			//add class to the database
			$query_add = "INSERT INTO class ( year, grade, class )
                       VALUES  ('$year','$grade' ,'$class')";
			if(mysql_query($query_add)){
				// class add successful.
				$_SESSION['log-info'] = "Add class Successfully.";
			}else{
				// SQL error occured.
				$_SESSION['log-err'] = "Sorry. Error occured. Please try again.";
			}
		}
	}
}

else{
	// Incomplet form submission.
	$_SESSION['log-err'] = "All the fields should be filled.";

}
$_SESSION['page'] = "addSubjects.php";
header('Location: ../');


?>